package andev.axplorer.Tiles;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by lzy1g on 2015/8/2.
 */
public class TilesAdapter extends BaseAdapter {
    private ArrayList<Map<String, Object>> mData;
    private Context mContext;

    public TilesAdapter(Context context, ArrayList<Map<String, Object>> data) {
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TilesLayout tilesLayout = new TilesLayout(mContext);
        Map<String, Object> tileMap = mData.get(position);
        tilesLayout.setTileMap(tileMap);
        tilesLayout.setFileName((String) tileMap.get("fileName"));
        tilesLayout.setFilePath((String) tileMap.get("filePath"));
        Object fileIcon = tileMap.get("fileIcon");
        if (fileIcon instanceof Integer)
            tilesLayout.setFileIcon((int) fileIcon);
        if (fileIcon instanceof Bitmap)
            tilesLayout.setFileIcon((Bitmap) fileIcon);
        return tilesLayout;
    }
}
